<?php
namespace App;

use Illuminate\Foundation\Auth\Type as Authenticatable;
use Illuminate\Database\Eloquent\Model;
use DB;
class Product extends Model
{
	public $table='product';
	public function getAll($goods_id){
    	return self::where('goods_id',$goods_id)->get()->toArray();
    }
     /**
     * 获取单条数据
     */
    public function getOne($goods_id,$product_attr){
        $res=DB::table('product')->where('goods_id',$goods_id)->where('product_attr',$product_attr)->select('product_id')->get();
        return array_map('get_object_vars',$res);
        //return $res;
    }
      /**
     * 添加单条
     */
    public function addOne($data){
        $re = self::insertGetId($data);
        if($re){
        	return $re;
        }
        return false;
    }
    public function checkedNum($goods_id,$product_attr,$product_number){
        $res=DB::table('product')->where('goods_id',$goods_id)->where('product_attr',$product_attr)->where('product_number','>=',$product_number)->get();
        return array_map('get_object_vars',$res);
    }
    /*
    查询该商品的货品数量
     */
    public function getNumber($goods_id,$product_attr){
        $res=DB::table('product')->where('goods_id',$goods_id)->where('product_attr',$product_attr)->select('product_number')->get();
        return array_map('get_object_vars',$res);
    }
    /**
     * 更新单个字段 原基础上 加减
     */
    // public function setNumber($id, $key, $value){
    //     $map = array(
    //         $this->key => $id
    //     );
    //     $this->db->set($key, $value, false);
    //     return $this->db->where($map)->update($this->table_name);
    // }
}